package cn.inno.login;

import cn.inno.controller.BaseController;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 登陆控制器
 *
 * @author LeungZengJian
 */
@Controller
public class LoginController extends BaseController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    @ResponseBody
    public String get(String name, String password, String sign) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject = this.loginService.get(name, password);
        } catch (Exception e) {
            this.writeExceptionJson(jsonObject, e);
        }
        return this.writeJson(jsonObject);
    }

    @GetMapping(value = {"/login", "/login.*", "logout"})
    public String get() {
        return "login";
    }

}
